home *** CD-ROM | disk | FTP | other *** search
/ Cre@te Online 2000 December / Cre@teOnline CD05.iso / MacSoft / XML ConsoleMax.sea / XML ConsoleMax / Required / swingall.jar / javax / swing / JToolBar.class (.txt) < prev    next >
Encoding:
Java Class File  |  1999-07-15  |  7.2 KB  |  264 lines

  1. package javax.swing;
  2.  
  3. import java.awt.Component;
  4. import java.awt.Container;
  5. import java.awt.Dimension;
  6. import java.awt.Graphics;
  7. import java.awt.Insets;
  8. import java.beans.PropertyChangeListener;
  9. import java.io.IOException;
  10. import java.io.ObjectOutputStream;
  11. import java.util.Hashtable;
  12. import javax.accessibility.Accessible;
  13. import javax.accessibility.AccessibleContext;
  14. import javax.swing.plaf.ToolBarUI;
  15.  
  16. public class JToolBar extends JComponent implements SwingConstants, Accessible {
  17.    private static final String uiClassID = "ToolBarUI";
  18.    private boolean paintBorder;
  19.    private Insets margin;
  20.    private boolean floatable;
  21.    private int orientation;
  22.    private static Hashtable listenerRegistry = null;
  23.  
  24.    public JToolBar() {
  25.       this(0);
  26.    }
  27.  
  28.    public JToolBar(int var1) {
  29.       this.paintBorder = true;
  30.       this.margin = null;
  31.       this.floatable = true;
  32.       this.orientation = 0;
  33.       this.checkOrientation(var1);
  34.       this.orientation = var1;
  35.       if (var1 == 1) {
  36.          ((Container)this).setLayout(new BoxLayout(this, 1));
  37.       } else if (SwingUtilities.isLeftToRight(this)) {
  38.          ((Container)this).setLayout(new BoxLayout(this, 0));
  39.       } else {
  40.          ((Container)this).setLayout(new RightToLeftToolBarLayout((1)null));
  41.       }
  42.  
  43.       ((JComponent)this).addPropertyChangeListener(new PropertyChangeHandler(this));
  44.       this.updateUI();
  45.    }
  46.  
  47.    public JButton add(Action var1) {
  48.       JButton var2 = new JButton((String)var1.getValue("Name"), (Icon)var1.getValue("SmallIcon"));
  49.       ((AbstractButton)var2).setHorizontalTextPosition(0);
  50.       ((AbstractButton)var2).setVerticalTextPosition(3);
  51.       ((AbstractButton)var2).setEnabled(var1.isEnabled());
  52.       ((AbstractButton)var2).addActionListener(var1);
  53.       ((Container)this).add(var2);
  54.       this.registerButtonForAction(var2, var1);
  55.       return var2;
  56.    }
  57.  
  58.    protected void addImpl(Component var1, Object var2, int var3) {
  59.       super.addImpl(var1, var2, var3);
  60.       if (var1 instanceof JButton) {
  61.          ((JButton)var1).setDefaultCapable(false);
  62.       }
  63.  
  64.    }
  65.  
  66.    public void addSeparator() {
  67.       Separator var1 = new Separator();
  68.       ((Container)this).add(var1);
  69.    }
  70.  
  71.    public void addSeparator(Dimension var1) {
  72.       Separator var2 = new Separator(var1);
  73.       ((Container)this).add(var2);
  74.    }
  75.  
  76.    private void checkOrientation(int var1) {
  77.       switch (var1) {
  78.          case 0:
  79.          case 1:
  80.             return;
  81.          default:
  82.             throw new IllegalArgumentException("orientation must be one of: VERTICAL, HORIZONTAL");
  83.       }
  84.    }
  85.  
  86.    protected PropertyChangeListener createActionChangeListener(JButton var1) {
  87.       return new ActionChangedListener(this, var1);
  88.    }
  89.  
  90.    public AccessibleContext getAccessibleContext() {
  91.       if (super.accessibleContext == null) {
  92.          super.accessibleContext = new AccessibleJToolBar(this);
  93.       }
  94.  
  95.       return super.accessibleContext;
  96.    }
  97.  
  98.    public Component getComponentAtIndex(int var1) {
  99.       int var2 = ((Container)this).getComponentCount();
  100.       if (var1 >= 0 && var1 < var2) {
  101.          Component[] var3 = ((Container)this).getComponents();
  102.          return var3[var1];
  103.       } else {
  104.          return null;
  105.       }
  106.    }
  107.  
  108.    public int getComponentIndex(Component var1) {
  109.       int var2 = ((Container)this).getComponentCount();
  110.       Component[] var3 = ((Container)this).getComponents();
  111.  
  112.       for(int var4 = 0; var4 < var2; ++var4) {
  113.          Component var5 = var3[var4];
  114.          if (var5 == var1) {
  115.             return var4;
  116.          }
  117.       }
  118.  
  119.       return -1;
  120.    }
  121.  
  122.    public Insets getMargin() {
  123.       return this.margin == null ? new Insets(0, 0, 0, 0) : this.margin;
  124.    }
  125.  
  126.    public int getOrientation() {
  127.       return this.orientation;
  128.    }
  129.  
  130.    public ToolBarUI getUI() {
  131.       return (ToolBarUI)super.ui;
  132.    }
  133.  
  134.    public String getUIClassID() {
  135.       return "ToolBarUI";
  136.    }
  137.  
  138.    public boolean isBorderPainted() {
  139.       return this.paintBorder;
  140.    }
  141.  
  142.    public boolean isFloatable() {
  143.       return this.floatable;
  144.    }
  145.  
  146.    protected void paintBorder(Graphics var1) {
  147.       if (this.isBorderPainted()) {
  148.          super.paintBorder(var1);
  149.       }
  150.  
  151.    }
  152.  
  153.    protected String paramString() {
  154.       String var1 = this.paintBorder ? "true" : "false";
  155.       String var2 = this.margin != null ? this.margin.toString() : "";
  156.       String var3 = this.floatable ? "true" : "false";
  157.       String var4 = this.orientation == 0 ? "HORIZONTAL" : "VERTICAL";
  158.       return super.paramString() + ",floatable=" + var3 + ",margin=" + var2 + ",orientation=" + var4 + ",paintBorder=" + var1;
  159.    }
  160.  
  161.    private void registerButtonForAction(JButton var1, Action var2) {
  162.       PropertyChangeListener var3 = this.createActionChangeListener(var1);
  163.       if (listenerRegistry == null) {
  164.          listenerRegistry = new Hashtable();
  165.       }
  166.  
  167.       listenerRegistry.put(var1, var3);
  168.       listenerRegistry.put(var3, var2);
  169.       var2.addPropertyChangeListener(var3);
  170.    }
  171.  
  172.    public void remove(Component var1) {
  173.       super.remove(var1);
  174.       if (var1 instanceof JButton) {
  175.          JButton var2 = (JButton)var1;
  176.          this.unregisterButtonForAction(var2);
  177.       }
  178.  
  179.    }
  180.  
  181.    public void setBorderPainted(boolean var1) {
  182.       if (this.paintBorder != var1) {
  183.          boolean var2 = this.paintBorder;
  184.          this.paintBorder = var1;
  185.          ((JComponent)this).firePropertyChange("borderPainted", var2, var1);
  186.          ((JComponent)this).revalidate();
  187.          ((Component)this).repaint();
  188.       }
  189.  
  190.    }
  191.  
  192.    public void setFloatable(boolean var1) {
  193.       if (this.floatable != var1) {
  194.          boolean var2 = this.floatable;
  195.          this.floatable = var1;
  196.          ((JComponent)this).firePropertyChange("floatable", var2, var1);
  197.          ((JComponent)this).revalidate();
  198.          ((Component)this).repaint();
  199.       }
  200.  
  201.    }
  202.  
  203.    public void setMargin(Insets var1) {
  204.       Insets var2 = this.margin;
  205.       this.margin = var1;
  206.       ((JComponent)this).firePropertyChange("margin", var2, var1);
  207.       ((JComponent)this).revalidate();
  208.       ((Component)this).repaint();
  209.    }
  210.  
  211.    public void setOrientation(int var1) {
  212.       this.checkOrientation(var1);
  213.       if (this.orientation != var1) {
  214.          int var2 = this.orientation;
  215.          this.orientation = var1;
  216.          if (var1 == 1) {
  217.             ((Container)this).setLayout(new BoxLayout(this, 1));
  218.          } else if (SwingUtilities.isLeftToRight(this)) {
  219.             ((Container)this).setLayout(new BoxLayout(this, 0));
  220.          } else {
  221.             ((Container)this).setLayout(new RightToLeftToolBarLayout((1)null));
  222.          }
  223.  
  224.          ((JComponent)this).firePropertyChange("orientation", var2, var1);
  225.          ((JComponent)this).revalidate();
  226.          ((Component)this).repaint();
  227.       }
  228.  
  229.    }
  230.  
  231.    public void setUI(ToolBarUI var1) {
  232.       super.setUI(var1);
  233.    }
  234.  
  235.    private void unregisterButtonForAction(JButton var1) {
  236.       if (listenerRegistry != null) {
  237.          ActionChangedListener var2 = (ActionChangedListener)listenerRegistry.remove(var1);
  238.          if (var2 != null) {
  239.             Action var3 = (Action)listenerRegistry.remove(var2);
  240.             if (var3 != null) {
  241.                ((AbstractButton)var1).removeActionListener(var3);
  242.                var3.removePropertyChangeListener(var2);
  243.             }
  244.  
  245.             var2.setTarget((JButton)null);
  246.          }
  247.       }
  248.  
  249.    }
  250.  
  251.    public void updateUI() {
  252.       this.setUI((ToolBarUI)UIManager.getUI(this));
  253.       ((Container)this).invalidate();
  254.    }
  255.  
  256.    private void writeObject(ObjectOutputStream var1) throws IOException {
  257.       var1.defaultWriteObject();
  258.       if (super.ui != null && this.getUIClassID().equals("ToolBarUI")) {
  259.          super.ui.installUI(this);
  260.       }
  261.  
  262.    }
  263. }
  264.